import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent, STPage } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { HttpService, SupDic } from 'lbf';
import { NzMessageService } from 'ng-zorro-antd';
import { ReuseTabService } from '@delon/abc';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-zyjk-zcbanli',
  templateUrl: './zcbanli.component.html',
})
export class ZyjkZcbanliComponent implements OnInit {
  tabs = ['办件信息', '材料影像'];
  dataset = [];
  PROJID = '1';
  DAD069 = '';
  params = { sname: 'BJXX_QUERY', queryparas: {} };
  datass = [];
  slSchema: SFSchema = {
    properties: {
      DAD095: {
        type: 'string',
        title: '',
        enum: [
          { label: '受理', value: '1' },
          { label: '不受理', value: '0' },
        ],
        // tslint:disable-next-line: no-object-literal-type-assertion
        ui: {
          widget: 'radio',
          // asyncData: () => of().pipe(delay(100)),
          change: console.log,
          grid: {
            span: 24,
          },
        } as SFRadioWidgetSchema,
        default: '1',
      },
      DAD098: {
        type: 'string',
        title: '不予受理原因',
        ui: {
          visibleIf: { DAD095: ['0'] },
          spanLabelFixed: 150,
          grid: { span: 24 },
        },
      },
    },
    ui: { grid: { span: 24 } },
    required: ['DAD098'],
  };

  constructor(
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
  ) {
    this.reuseTabService.title = '基本医疗保险转出办理';
  }

  sffschema: SFSchema = {
    properties: {
      AAC002: {
        title: '证件号',
        type: 'string',
        ui: {
          hidden: true,
        },
      },
      AAC003: {
        title: '姓名',
        type: 'string',
        ui: {
          hidden: true,
        },
      },
    },
    ui: {
      grid: { span: 12 },
      spanLabelFixed: 150,
    },
  };

  // 本地获取数据
  ppdl: SFSchema = {
    properties: {
      AAC001: {
        title: '个人编码',
        type: 'string',
        readOnly: true,
      },
      AAE140: {
        title: '险种类型',
        type: 'string',
        enum: [{ label: '职工基本医疗310', value: '310' }],
        default: '310',
        readOnly: true,
      },
      DAC133: {
        type: 'string',
        title: '转移档案号',
        readOnly: true,
      },

      AAC002: {
        title: '社会保障号',
        type: 'string',
        readOnly: true,
      },

      AAC003: {
        title: '姓名',
        type: 'string',
        readOnly: true,
      },

      AAC004: {
        title: '性别',
        type: 'string',
        readOnly: true,
        enum: [
          { label: '男', value1: '1' },
          { label: '女', value: '2' },
        ],
      },

      AAC010: {
        title: '户籍地地址',
        type: 'string',
        ui: { hidden: true },
      },

      AAB004: {
        title: '转出单位名称',
        type: 'string',
        readOnly: true,
      },

      AAC049: {
        title: '参加工作时间',
        type: 'string',
        readOnly: true,
      },

      AAB305: {
        title: '首保地个人缴费时间',
        type: 'string',
        readOnly: true,
      },

      AAE030: {
        title: '本地缴费起始时间',
        type: 'string',
        readOnly: true,
      },

      AAE031: {
        title: '本地缴费终止时间',
        type: 'string',
        readOnly: true,
      },

      LNZHYE: {
        title: '历年结转额',
        type: 'string',
        readOnly: true,
      },

      BNZHYE: {
        title: '本年账户额',
        type: 'string',
        readOnly: true,
      },
      AAE035: {
        title: '转移日期',
        type: 'string',
        readOnly: true,
      },
      AAE473: {
        title: '转移账户类别',
        type: 'string',
        readOnly: true,
        enum: this.supDic.getSFDic('AAE473'),
        default: '1',
        ui: {
          widget: 'select',
        },
      },
      AAC105: {
        title: '转移地域范围',
        type: 'string',
        readOnly: true,
        enum: this.supDic.getSFDic('BAE011'),
        ui: {
          widget: 'select',
        },
      },
      SBJG: {
        title: '对方社保名称',
        type: 'string',
        readOnly: true,
      },
      RECACCNO: {
        title: '银行帐号',
        type: 'string',
        readOnly: true,
      },
      RECACCNAMECN: {
        title: '账户名称',
        type: 'string',
        readOnly: true,
      },
      RECBANKNAME: {
        title: '银行名称',
        type: 'string',
        readOnly: true,
      },
      SBJGDZ: {
        title: '地址',
        type: 'string',
        readOnly: true,
      },
      SBJGYB: {
        title: '邮编',
        type: 'string',
        readOnly: true,
      },
      LXHBH: {
        title: '联系函编号',
        type: 'string',
        readOnly: true,
      },
      AAE013: {
        type: 'string',
        title: '备注',
        readOnly: true,
        ui: {
          grid: { span: 24 },
        },
      },
    },
    ui: {
      grid: { span: 8 },
      spanLabelFixed: 150,
    },
  };

  bbColumns: STColumn[] = [
    { title: '缴费起始年月', index: 'AAE041' },
    { title: '缴费终止年月', index: 'AAE042' },
    { title: '基本医疗保险类型', index: 'YBLX' },
    { title: '参保缴费月数小计', index: 'AAE202' },
    { title: '统筹地区经办机构名称', index: 'AAC072' },
    { title: '统筹地区行政区划代码', index: 'AAB301' },
    { title: '备注', index: 'AAE013' },
  ];

  tabMode = 'bjxx';
  @ViewChild('bbst', { static: false }) bbst: STComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('slxx', { static: false }) slxx: SFComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;
  @ViewChild('sffd', { static: false }) sffd: SFComponent;
  @ViewChild('sf1', { static: false }) sf1: SFComponent;

  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    { title: '材料数量', index: 'STUFFNUM', width: '25%' },
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },
  ];

  page: STPage = {
    show: false,
  };

  ngOnInit() {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 打开情况下再次传入值
  _onReuseInit(): void {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }

  // 界面赋值
  YB_QUERY() {
    this.lbservice
      .lbservice('YB_QUERY', { para: { PROJID: this.PROJID } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf.formData = JSON.parse(resdata.message);
          this.sf.reset();
          // 页面加载的时候调用后台获取值
          this.Yb_fanh();
        }
      });
  }

  // 材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCL_QUERY', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }

  // 保存
  lc_save(value1: any) {
    // tslint:disable-next-line: all
    if (value1.DAD095 == '0') {
      if (!this.slxx.valid) {
        return this.msgSrv.error('没有填写必填项');
      }
      this.lbservice
        .lbservice('P_Lc_Save', {
          para: {
            PROJID: this.PROJID,
            sf: this.sf.value,
            slxx: this.slxx.value,
            DAD069: this.DAD069,
            bbst: this.bbst.data,
            sf1: this.sf1.value,
          },
        })
        .then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          } else {
            this.msgSrv.info('成功');
            this.sf.reset();
          }
        });
    } else {
      this.lbservice
        .lbservice('P_Lc_Save', {
          para: {
            PROJID: this.PROJID,
            sf: this.sf.value,
            slxx: this.slxx.value,
            DAD069: this.DAD069,
            bbst: this.bbst.data,
            sf1: this.sf1.value,
          },
        })
        .then(resdata => {
          if (resdata.code < 1) {
            this.msgSrv.error(resdata.errmsg);
          } else {
            this.msgSrv.info('成功');
            this.sf.reset();
          }
        });
    }
  }
  // 根据身份证返回前端数据
  Yb_fanh() {
    this.lbservice
      .lbservice('Yb_fanh', {
        para: { PROJID: this.PROJID, sf: this.sf.value },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          console.log('根据身份证返回前端数据');
          console.log(resdata);
          this.sf1.formData = resdata.message.list[0];
          this.sf1.reset();
        }
      });
  }
  // 生成数据
  Yb_shenj() {
    this.lbservice
      .lbservice('Yb_shenj', {
        para: { PROJID: this.PROJID, sf: this.sf1.value },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          console.log('生成数据');
          console.log(resdata);
          // resdata.message.list[0];
          this.datass = resdata.message.list;
          this.bbst.reset();
          this.pl.active2 = true;
          this.pl.active1 = false;
        }
      });
  }

  // disabled: true,
  // tslint:disable-next-line: member-ordering
  pl = {
    pname: '',
    active: false,
    disabled: true,
    pname1: '本地数据',
    active1: true,
    pname2: '数据详情',
    active2: false,
    icon1: 'caret-right',
  };
}
